#define _CRT_SECURE_NO_WARNINGS
#include <iostream>

using namespace std;
typedef long long LL;
const int N = 15;
int n;
LL r[N], m[N];
LL qmul(LL a, LL b, LL p)
{
	LL ret = 0;
	while (b)
	{
		if (b & 1) ret = (ret + a) % p;
		b >>= 1;
		a = (a + a) % p;
	}
	return ret;
}
void exgcd(LL a, LL b, LL& x, LL& y)
{
	if (b == 0)
	{
		x = 1, y = 0;
		return;
	}
	LL x1, y1;
	exgcd(b, a % b, x1, y1);
	x = y1, y = x1 - a / b * y1;
}
LL crt()
{
	LL M = 1;
	for (int i = 1; i <= n; i++) M *= m[i];
	LL ret = 0;
	for (int i = 1; i <= n; i++)
	{
		LL c = M / m[i];
		LL x, y;
		exgcd(c, m[i], x, y);
		x = (x % m[i] + m[i]) % m[i];
		// c * x * r[i]
		ret = (ret + qmul(qmul(c, x, M), r[i], M)) % M;
	}
	return ret;
}
int main() 
{
	cin >> n;
	LL M = 1;
	LL ret = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> m[i] >> r[i];
	}
	
	cout << crt() << endl;
	return 0;
}